package com.example.JavaWebDemo8.View;

import com.example.JavaWebDemo8.DAO.JDBCUtils;
import com.example.JavaWebDemo8.DAO.Student;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "studentServlet", value = "/student-Servlet")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + "学生信息" + "</h1>");

        Student student;
        out.println("<p>");
        out.println("输出结果：");
        try {
            student = JDBCUtils.query("select * from s where sno=?", "10000");
            out.println(student.toString());
        } catch (Exception e) {
            out.println("出现异常"+e.toString());
            e.printStackTrace();
        }

        out.println("</p>");
        out.println("</body></html>");

    }
}
